
/*** Appendix do-file ***

	War, Solidarity, and Welfare Attitudes:
	Survey Evidence from the War in Ukraine
	
	By Frizell, Jakob, Viktoriia Muliavka, Herbert Obinger, and Carina Schmitt,
	(2025) Journal of European Public Policy.

	January 2025

 All output produced with Stata 17, except table 13 a/b
 for which R-code is provided.
 
 User-written commands for Stata necessary to run the code:
 - asdoc
	Shah, A. (2018). "asdoc:  Create high-quality tables in MS Word from Stata output"
 - spmap
	Pisati, M. (2018). "SPMAP: Stata module to visualize spatial data"
 - sensemakr
	Cinelli et al. (2024). "Sensemakr: Sensitivity Analysis Tools for OLS in R and Stata"
 
 All of which can be installed through [ssc install]

ssc install asdoc
ssc install spmap
ssc install sensemakr
 
 */
 
 
 
******************************************************************************

************ SECTION A: Survey Details and variable descriptives *************

	*Default graph font
 graph set window fontface default

* Load Ukraine database
		use "GEO\UKR1db.dta", clear

 **** Localities map (current localities)
		
		   spmap using "GEO\UKR1coord_wmproj.dta", id(id) ndsize(vthin) ndocolor(gs10) osize(vthin ..) point(data("GEO\resp_locations_post.dta") xcoord(X_wmp) ycoord(Y_wmp) prop(resp) by(urban) fcolor(blue%30 red%30) osize(vthin) ocolor(black) size(small)) ///
 title("Figure A1: Ukraine, survey respondents by current place of residence", size(medsmall)) note("Note: Post-invasion geographical distribution of respondents for which location data is available (936/1,001)." "Circle size corresponds to the number of respondents in each locality." "Red circles denote Cities (637 respondents across 140 localities);" "Blue circles denote villages and towns (299 respondents across 276 localities)." "Locations are centroids of ADM4 localities as given by UNOCHA.", size(vsmall)) 
 
  graph export "Appendix output\fig_A1_Ukraine respondent localitites.png", width(5000) replace




  

***** DV component descriptives - Table A1-A3 *****

use "Ukraine_warwel_survey_2023_red_noid.dta", clear


	*Social spending priority
asdoc sum C5*, dec(2) label ///
  save(Appendix output\table_A1.doc) replace title(Table A1. Descriptive statistics: Spending Priorities)


	*Altruism
	asdoc sum D3*, dec(2) ///
  save(Appendix output\table_A2.doc) replace title(Table A2. Descriptive statistics: Altrusim)


  * Fairness demand
  	asdoc sum C1C, dec(2) ///
  save(Appendix output\table_A3.doc) replace title(Table A3. Descriptive statistics: Fairness)

	* Final fomatting in Word.
  
 
  
  
	**** TABLE 4 & 5 - Final variable descriptives ****

	use "Ukraine_warwel_survey_2023_red_noid.dta", clear
	
*** Continuous variables

	*Full sample
  asdoc sum relsocprio relnatalt C1C fat20gtwlnnorm B1invnorm ///
  incGr HHsize, dec(2) ///
  save(Appendix output\table_A4_FULL.doc) replace title(Table A4)
	*Reduced sample (non-movers)
    asdoc sum relsocprio relnatalt C1C fat20gtwlnnorm B1invnorm ///
  incGr HHsize if mov==0, dec(2) ///
  save(Appendix output\table_A4_REDUCED.doc) replace title(Table A4)
  
  *** Categorical variables
  
    ** (re)generate dummy DVs as in logit regression
			gen relsocprio_dum=1 if relsocprio>0.777777 & relsocprio!=.
			replace relsocprio_dum=0 if relsocprio_dum==. & relsocprio!=.
			gen relnatalt_dum=1 if relnatalt>0 & relnatalt!=.
			replace relnatalt_dum=0 if relnatalt_dum==. & relnatalt!=.
			gen C1C_dum=1 if C1C==10
			replace C1C_dum=0 if C1C!=. & C1C!=10
	*Full sample
  asdoc tab1 relsocprio_dum relnatalt_dum C1C_dum AgeGr6 edu3 gender retired unemp milvet disab pdam IDP urban LANG , dec(2) nocf ///
  save(Appendix output\table_A5_FULL.doc) replace
   * Reduced sample (non-movers)
   asdoc tab1 relsocprio_dum relnatalt_dum C1C_dum AgeGr6 edu3 gender retired unemp milvet disab pdam IDP urban LANG if mov==0, dec(2) nocf ///
  save(Appendix output\table_A5_REDUCED.doc) replace
  
  
  * Tables combined and formatted in word.
  
  




******************************************************************************

************ SECTION B: Alternative models and robustness checks *************


use "Ukraine_warwel_survey_2023_red_noid.dta", clear



		****/// TABLE B1-B3: OLS regressions \\\***


	***** MINIMAL / BASELINE / EXPANDED SPECIFICATIONS ********




************ Regressions (A): Table B1 Relative social spending prio ********************



	*WAR EXPOSURE
eststo: regress relsocprio fat20gtwlnnorm if mov==0, vce(cl ADM4nom)
eststo: regress relsocprio fat20gtwlnnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0, vce(cl ADM4nom)
eststo: regress relsocprio fat20gtwlnnorm i.gender i.AgeGr6 i.edu3 incGr HHsize i.retired i.unemp i.milvet i.disab i.pdam i.IDP i.urban i.LANG i.preA1n if mov==0, vce(cl ADM4nom)


	
	*FINANCIAL IMPACT
eststo: regress relsocprio B1invnorm if mov==0
eststo: regress relsocprio B1invnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0
eststo: regress relsocprio B1invnorm i.gender i.AgeGr6 i.edu3 incGr HHsize i.retired i.unemp i.milvet i.disab i.pdam i.IDP i.urban i.LANG i.preA1n if mov==0






esttab using "Appendix output\table_B1-3.rtf", se r2 b(3) nogaps compress ///
 title("Table B1: Relative Social Policy Expenditure Priority (OLS)") ///
 order(fat20gtwlnnorm B1invnorm) drop(*preA1n) nobase ///
 addnote("Standard errors clustered on locality for models 1-3.") replace

eststo clear




**** Regressions (B): Table B2 - RELATIVE NATIONAL ALTRUISM *********


	*WAR EXPOSURE
eststo: regress relnatalt fat20gtwlnnorm if mov==0, vce(cl ADM4nom)
eststo: regress relnatalt fat20gtwlnnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0, vce(cl ADM4nom)
eststo: regress relnatalt fat20gtwlnnorm i.gender i.AgeGr6 i.edu3 incGr HHsize i.retired i.unemp i.milvet i.disab i.pdam i.IDP i.urban i.LANG i.preA1n if mov==0, vce(cl ADM4nom)




	
	*FINANCIAL IMPACT
eststo: regress relnatalt B1invnorm if mov==0
eststo: regress relnatalt B1invnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0
eststo: regress relnatalt B1invnorm i.gender i.AgeGr6 i.edu3 incGr HHsize i.retired i.unemp i.milvet i.disab i.pdam i.IDP i.urban i.LANG i.preA1n if mov==0





esttab using "Appendix output\table_B1-3.rtf", se r2 b(3) nogaps compress ///
 title("Table B2: Relative National Altruism (OLS)") ///
 order(fat20gtwlnnorm B1invnorm) drop(*preA1n) nobase ///
 addnote("Standard errors clustered on locality for models 1-3.") append
 
 eststo clear


 
 
 

****** REGRESSIONS (C): Table B3 - Fairness / distribution 


*Gov. assure fair distribution
	*WAR EXPOSURE
eststo: regress C1C fat20gtwlnnorm if mov==0, vce(cl ADM4nom)
eststo: regress C1C fat20gtwlnnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0, vce(cl ADM4nom)
eststo: regress C1C fat20gtwlnnorm i.gender i.AgeGr6 i.edu3 incGr HHsize i.retired i.unemp i.milvet i.disab i.pdam i.IDP i.urban i.LANG i.preA1n if mov==0, vce(cl ADM4nom)


	
	*FINANCIAL IMPACT
eststo: regress C1C B1invnorm if mov==0
eststo: regress C1C B1invnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0
eststo: regress C1C B1invnorm i.gender i.AgeGr6 i.edu3 incGr HHsize i.retired i.unemp i.milvet i.disab i.pdam i.IDP i.urban i.LANG i.preA1n if mov==0




esttab using "Appendix output\table_B1-3.rtf", se r2 b(3) nogaps compress ///
 title("Table B3: Ensuring fairness of burdens (OLS)") ///
 order(fat20gtwlnnorm B1invnorm) drop(*preA1n) nobase ///
 addnote("Standard errors clustered on locality for models 1-3.") append
 
 eststo clear

 

 
 
 

  ********/// OMITTED VARIABVLE SENSITIVITY ANALYSIS \\\********
  
  
  
  use "Ukraine_warwel_survey_2023_red_noid.dta", clear
  

 ********************** TABLE B4: OBV SENSITIVITY ANALYSIS *******************
 
*SOCIAL POLICY PRIORITY 
  *(A) War exposure
  sensemakr relsocprio fat20gtwlnnorm i.gender i.AgeGr6 i.edu3 incGr HHsize i.retired ///
  i.unemp i.milvet i.disab i.pdam i.IDP i.urban i.LANG i.preA1n if mov==0, ///
  treat(fat20gtwlnnorm) gbenchmark(i.gender i.AgeGr6 i.edu3 incGr) kd(1)
  
 *(B) Financial impact
  sensemakr relsocprio B1invnorm i.gender i.AgeGr6 i.edu3 incGr HHsize i.retired ///
  i.unemp i.milvet i.disab i.pdam i.IDP i.urban i.LANG i.preA1n if mov==0, ///
  treat(B1invnorm) gbenchmark(i.gender i.AgeGr6 i.edu3 incGr) kd(1)
  
*NATIONAL SOLIDARITY  
  *(A) War exposure
 sensemakr relnatalt fat20gtwlnnorm i.gender i.AgeGr6 i.edu3 incGr HHsize i.retired ///
 i.unemp i.milvet i.disab i.pdam i.IDP i.urban i.LANG i.preA1n if mov==0, ///
 treat(fat20gtwlnnorm) gbenchmark(i.gender i.AgeGr6 i.edu3 incGr) kd(1)
 
  *(B) Financial impact
  sensemakr relnatalt B1invnorm i.gender i.AgeGr6 i.edu3 incGr HHsize i.retired ///
 i.unemp i.milvet i.disab i.pdam i.IDP i.urban i.LANG i.preA1n if mov==0, ///
 treat(B1invnorm) gbenchmark(i.gender i.AgeGr6 i.edu3 incGr) kd(1)
 
*FAIRNESS DEMAND 
  *(A) War exposure
 sensemakr C1C fat20gtwlnnorm i.gender i.AgeGr6 i.edu3 incGr HHsize i.retired ///
 i.unemp i.milvet i.disab i.pdam i.IDP i.urban i.LANG i.preA1n if mov==0, ///
 treat(fat20gtwlnnorm) gbenchmark(i.gender i.AgeGr6 i.edu3 incGr) kd(1)
 
 *(B) Financial impact
   sensemakr C1C B1invnorm i.gender i.AgeGr6 i.edu3 incGr HHsize i.retired ///
 i.unemp i.milvet i.disab i.pdam i.IDP i.urban i.LANG i.preA1n if mov==0, ///
 treat(B1invnorm) gbenchmark(i.gender i.AgeGr6 i.edu3 incGr) kd(1)
 
 
 *** Output manually exported to .xlsx and edited.
 
 
 
 
 ************************  FIGURES B1-B3  *****************************
 
 
 *SOCIAL POLICY PRIORITY 
 
	**** FIGURE B1 ****
 
 *(A) War exposure
  sensemakr relsocprio fat20gtwlnnorm i.gender i.AgeGr6 i.edu3 incGr HHsize i.retired ///
  i.unemp i.milvet i.disab i.pdam i.IDP i.urban i.LANG i.preA1n if mov==0, ///
  treat(fat20gtwlnnorm) gbenchmark(i.gender i.AgeGr6 i.edu3 incGr) gname("Baseline") tcontourplot clim(0 0.1)
	graph save "Appendix output\temp\SP_Wexp.gph", replace
  
 *(B) Financial impact
  sensemakr relsocprio B1invnorm i.gender i.AgeGr6 i.edu3 incGr HHsize i.retired ///
  i.unemp i.milvet i.disab i.pdam i.IDP i.urban i.LANG i.preA1n if mov==0, ///
  treat(B1invnorm) gbenchmark(i.gender i.AgeGr6 i.edu3 incGr) gname("Baseline") tcontourplot
  graph save "Appendix output\temp\SP_FI.gph", replace
  
    graph combine "Appendix output\temp\SP_Wexp.gph" "Appendix output\temp\SP_FI.gph" , ///
col(2) title("Figure B1: Sensitivity to OVB, Social Expenditure Priority models", pos(11) size(medsmall) margin(medsmall)) b1title("(A) War exposure 									(B) Financial impact", size(8pt)) ///
imargin(2 2 2 2) graphregion(margin(l=1 r=1 b=10 t=10))
graph export "Appendix output\fig_B1.png", width(3000) replace


 
 *NATIONAL SOLIDARITY
 
 	**** FIGURE B2 ****
 
 *(A) War exposure
 sensemakr relnatalt fat20gtwlnnorm i.gender i.AgeGr6 i.edu3 incGr HHsize i.retired ///
 i.unemp i.milvet i.disab i.pdam i.IDP i.urban i.LANG i.preA1n if mov==0, ///
 treat(fat20gtwlnnorm) gbenchmark(i.gender i.AgeGr6 i.edu3 incGr) gname("Baseline") tcontourplot
 graph save "Appendix output\temp\NA_Wexp.gph", replace
 
  *(B) Financial impact
  sensemakr relnatalt B1invnorm i.gender i.AgeGr6 i.edu3 incGr HHsize i.retired ///
 i.unemp i.milvet i.disab i.pdam i.IDP i.urban i.LANG i.preA1n if mov==0, ///
 treat(B1invnorm) gbenchmark(i.gender i.AgeGr6 i.edu3 incGr) gname("Baseline") tcontourplot
 graph save "Appendix output\temp\NA_FI.gph", replace
 
     graph combine "Appendix output\temp\NA_Wexp.gph" "Appendix output\temp\NA_FI.gph" , ///
col(2) title("Figure B2: Sensitivity to OVB, Relative National Solidarity models", pos(11) size(medsmall) margin(medsmall)) b1title("(A) War exposure 									(B) Financial impact", size(8pt)) ///
imargin(2 2 2 2) graphregion(margin(l=1 r=1 b=10 t=10))
graph export "Appendix output\fig_B2.png", width(3000) replace
 

 
 *FAIRNESS DEMAND
 
 
 	**** FIGURE B3 ****
 
 *(A) War exposure
  sensemakr C1C fat20gtwlnnorm i.gender i.AgeGr6 i.edu3 incGr HHsize i.retired ///
 i.unemp i.milvet i.disab i.pdam i.IDP i.urban i.LANG i.preA1n if mov==0, ///
 treat(fat20gtwlnnorm) gbenchmark(i.gender i.AgeGr6 i.edu3 incGr) gname("Baseline") tcontourplot
 graph save "Appendix output\temp\FD_Wexp.gph", replace
 
 *(B) Financial impact
   sensemakr C1C B1invnorm i.gender i.AgeGr6 i.edu3 incGr HHsize i.retired ///
 i.unemp i.milvet i.disab i.pdam i.IDP i.urban i.LANG i.preA1n if mov==0, ///
 treat(B1invnorm) gbenchmark(i.gender i.AgeGr6 i.edu3 incGr) gname("Baseline") tcontourplot
 graph save "Appendix output\temp\FD_FI.gph", replace
 
 
     graph combine "Appendix output\temp\FD_Wexp.gph" "Appendix output\temp\FD_FI.gph" , ///
col(2) title("Figure B3: Sensitivity to OVB, Fairness Demand models", pos(11) ///
 size(medsmall) margin(medsmall)) b1title("(A) War exposure 									(B) Financial impact", size(8pt)) ///
imargin(2 2 2 2) graphregion(margin(l=1 r=1 b=10 t=10))
graph export "Appendix output\fig_B3.png", width(3000) replace
 
 
 

 
 

*********************** Table B5 - LOGIT REGRESSIONS ****************************** 

  use "Ukraine_warwel_survey_2023_red_noid.dta", clear

*** Dichotomizing DVs
			gen relsocprio_dum=1 if relsocprio>0.777777 & relsocprio!=.
			replace relsocprio_dum=0 if relsocprio_dum==. & relsocprio!=.
			gen relnatalt_dum=1 if relnatalt>0 & relnatalt!=.
			replace relnatalt_dum=0 if relnatalt_dum==. & relnatalt!=.
			gen C1C_dum=1 if C1C==10
			replace C1C_dum=0 if C1C!=. & C1C!=10


			* Logit regressions with basic controls *

eststo: logit relsocprio_dum fat20gtwlnnorm i.gender i.AgeGr6 i.edu3 ///
 incGr if mov==0, vce(cl ADM4nom)
eststo: logit relsocprio_dum B1invnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0

eststo: logit relnatalt_dum fat20gtwlnnorm i.gender i.AgeGr6 i.edu3 ///
 incGr if mov==0, vce(cl ADM4nom)
eststo: logit relnatalt_dum B1invnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0

eststo: logit C1C_dum fat20gtwlnnorm i.gender i.AgeGr6 i.edu3 ///
 incGr if mov==0, vce(cl ADM4nom)
eststo: logit C1C_dum B1invnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0

	esttab using "Appendix output\table_B5.rtf", se pr2 b(3) nogaps compress ///
 title("Table B5: Dichotomous DVs (logit regressions)") ///
 order(fat20gtwlnnorm B1invnorm) nobase ///
 addnote("Standard errors clustered on locality for models 1, 3, 5. Coefficients reported as log odds.") replace
  eststo clear

  

  
  
  
  
  ************************** /// ALTERNATIVE SPECS \\\ **************************

	***** TABLE B6: Relative Social Policy Expenditure Priority (OLS) – Alternative DVs

	  use "Ukraine_warwel_survey_2023_red_noid.dta", clear
	
	
	**** RELATIVE SOC POL PRIO 
			*Standard
	eststo:	regress relsocprio fat20gtwlnnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0, vce(cl ADM4nom)
	eststo:	regress relsocprio B1invnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0
	
	
		*Excluding defence item
				*Generate social prio variable, exlc. defence
				egen nodef = rowmean(C5A C5C C5D C5E C5F C5G C5H C5I)
				gen relsocprio_nodef=C5G-nodef
	eststo:	regress relsocprio_nodef fat20gtwlnnorm i.gender i.AgeGr6 ///
		i.edu3 incGr if mov==0, vce(cl ADM4nom)
	eststo: regress relsocprio_nodef B1invnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0
	
		*Post war spending priority
	eststo:	regress relsocpriopost fat20gtwlnnorm i.gender i.AgeGr6 ///
		i.edu3 incGr if mov==0, vce(cl ADM4nom)
	eststo:	regress relsocpriopost B1invnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0
	
	esttab using "Appendix output\table_B6-16.rtf", se r2 b(3) nogaps compress ///
 title("Table B6: Relative Social Policy Expenditure Priority (OLS) - Alternative DVs") ///
 order(fat20gtwlnnorm B1invnorm) nobase ///
 addnote("Standard errors clustered on locality for models 1, 3, 5.") append
 
 eststo clear

	
	
	
	
***** TABLE B7: RELATIVE SOC POL PRIO; original component items 

	  use "Ukraine_warwel_survey_2023_red_noid.dta", clear

	*** Table B7(a)
	
	eststo: regress C5A fat20gtwlnnorm i.gender i.AgeGr6 ///
		i.edu3 incGr if mov==0, vce(cl ADM4nom)
	eststo: regress C5A B1invnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0
	
	eststo: regress C5B fat20gtwlnnorm i.gender i.AgeGr6 ///
		i.edu3 incGr if mov==0, vce(cl ADM4nom)
	eststo: regress C5B B1invnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0
	
	eststo: regress C5C fat20gtwlnnorm i.gender i.AgeGr6 ///
		i.edu3 incGr if mov==0, vce(cl ADM4nom)
	eststo: regress C5C B1invnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0
	
	esttab using "Appendix output\table_B6-16.rtf", se r2 b(3) nogaps compress ///
 title("Table B7(a): Expenditure Priority (OLS) - Original components") ///
 order(fat20gtwlnnorm B1invnorm) nobase ///
 addnote("Standard errors clustered on locality for models 1, 3, 5.") append
 
 eststo clear
 
 
	*** Table B7(b)
 
 	eststo: regress C5D fat20gtwlnnorm i.gender i.AgeGr6 ///
		i.edu3 incGr if mov==0, vce(cl ADM4nom)
	eststo: regress C5D B1invnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0
	
	eststo: regress C5E fat20gtwlnnorm i.gender i.AgeGr6 ///
		i.edu3 incGr if mov==0, vce(cl ADM4nom)
	eststo: regress C5E B1invnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0
	
	eststo: regress C5F fat20gtwlnnorm i.gender i.AgeGr6 ///
		i.edu3 incGr if mov==0, vce(cl ADM4nom)
	eststo: regress C5F B1invnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0
	
	esttab using "Appendix output\table_B6-16.rtf", se r2 b(3) nogaps compress ///
 title("Table B7(b): Expenditure Priority (OLS) - Original components") ///
 order(fat20gtwlnnorm B1invnorm) nobase ///
 addnote("Standard errors clustered on locality for models 1, 3, 5.") append
	
	eststo clear
	
	
	*** Table B7(c)
 
 	eststo: regress C5G fat20gtwlnnorm i.gender i.AgeGr6 ///
		i.edu3 incGr if mov==0, vce(cl ADM4nom)
	eststo: regress C5G B1invnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0
	
	eststo: regress C5H fat20gtwlnnorm i.gender i.AgeGr6 ///
		i.edu3 incGr if mov==0, vce(cl ADM4nom)
	eststo: regress C5H B1invnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0
	
	eststo: regress C5I fat20gtwlnnorm i.gender i.AgeGr6 ///
		i.edu3 incGr if mov==0, vce(cl ADM4nom)
	eststo: regress C5I B1invnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0
	
	esttab using "Appendix output\table_B6-16.rtf", se r2 b(3) nogaps compress ///
 title("Table B7(c): Expenditure Priority (OLS) - Original components") ///
 order(fat20gtwlnnorm B1invnorm) nobase ///
 addnote("Standard errors clustered on locality for models 1, 3, 5.") append
 
	eststo clear
 
	
	
	
	
	
	
	***** NATIONAL SOLIDARITY - ALTERNATIVE MODELS *******

	***** TABLE B8 ****
	
	use "Ukraine_warwel_survey_2023_red_noid.dta", clear
	
	*** Main
eststo: regress relnatalt fat20gtwlnnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0, vce(cl ADM4nom)
eststo: regress relnatalt B1invnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0

	*** Two IVs included together
eststo: regress relnatalt B1invnorm fat20gtwlnnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0, vce(cl ADM4nom)

*It could be that the results are solely driven by a decreased solidarity with
*non-Ukraineans; more war-exposed individuals would down-prioritize non-Ukrainean
	* people, thus driving up the relative priority of Ukranians, including
	*"poeple from other regions".

	*Excluding item concerning people from outside of Ukraine ("cosmopolitan"")
	gen avalt_nocos=(D3A+D3B+D3C)/3
	gen relnatalt_nocos=D3C-avalt_nocos
	
	*Excluding item concerning people from neighbourhood ("local")
	gen avalt_noloc=(D3B+D3C+D3D)/3
	gen relnatalt_noloc=D3C-avalt_noloc

	

eststo: regress relnatalt_nocos fat20gtwlnnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0, vce(cl ADM4nom)
eststo: regress relnatalt_nocos B1invnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0

eststo: regress relnatalt_noloc fat20gtwlnnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0, vce(cl ADM4nom)
eststo: regress relnatalt_noloc B1invnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0


	esttab using "Appendix output\table_B6-16.rtf", se r2 b(3) nogaps compress ///
 title("Table B8: National Solidarity, alternative models") ///
 order(fat20gtwlnnorm B1invnorm) nobase ///
 addnote("Standard errors clustered on locality for models 1, 3, 4, & 6.") append
 
 eststo clear
 
 
 
 
	**** TABLE B9 ****
	
	 use "Ukraine_warwel_survey_2023_red_noid.dta", clear

*Absolute Solidarity: Direct war exposure
eststo: regress relnatalt fat20gtwlnnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0, vce(cl ADM4nom)
eststo: regress D3A fat20gtwlnnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0, vce(cl ADM4nom)
eststo: regress D3B fat20gtwlnnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0, vce(cl ADM4nom)
eststo: regress D3C fat20gtwlnnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0, vce(cl ADM4nom)
eststo: regress D3D fat20gtwlnnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0, vce(cl ADM4nom)

	esttab using "Appendix output\table_B6-16.rtf", se r2 b(3) nogaps compress ///
 title("Table B9: Altruism, original components (direct war exposure)") ///
 order(fat20gtwlnnorm) nobase ///
 addnote("Standard errors clustered on locality in all models.") append
  eststo clear
  
  
	**** TABLE B10 ****

	*Absolute Solidarity: Financial exposure 
eststo: regress relnatalt B1invnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0
eststo: regress D3A B1invnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0
eststo: regress D3B B1invnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0
eststo: regress D3C B1invnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0
eststo: regress D3D B1invnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0

	esttab using "Appendix output\table_B6-16.rtf", se r2 b(3) nogaps compress ///
 title("Table B10: Altruism, original components (financial impact)") ///
 order(B1invnorm) nobase ///
 addnote("") append
  eststo clear




**************** RELATIVE NATIONAL TRUST ****************************
	
	*Alternative to altruism indicator of solidarity*
	
	*** TABLE B11: Relative national trust (war exposure) ***
	
	use "Ukraine_warwel_survey_2023_red_noid.dta", clear
	
	*Generate relative national trust variable (equivalent to altruism)
	egen avtrust=rowmean(D2A D2B D2C)
	gen relnattrust=D2C-avtrust
	*hist relnattrust

	
eststo: regress relnattrust fat20gtwlnnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0, vce(cl ADM4nom)
eststo: regress D2A fat20gtwlnnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0, vce(cl ADM4nom)
eststo: regress D2B fat20gtwlnnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0, vce(cl ADM4nom)
eststo: regress D2C fat20gtwlnnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0, vce(cl ADM4nom)

	esttab using "Appendix output\table_B6-16.rtf", se r2 b(3) nogaps compress ///
 title("Table B11: Relative national trust and original components (war exposure)") ///
 order(fat20gtwlnnorm) nobase ///
 addnote("Standard errors clustered on locality in all models.") append
  eststo clear
  
  
  
	*** TABLE B12: Relative national trust (financial impact) ***


eststo: regress relnattrust B1invnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0
eststo: regress D2A B1invnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0
eststo: regress D2B B1invnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0
eststo: regress D2C B1invnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0

	esttab using "Appendix output\table_B6-16.rtf", se r2 b(3) nogaps compress ///
 title("Table B12: Relative national trust and original components (financial impact)") ///
 order(B1invnorm) nobase ///
 addnote(" ") append
  eststo clear




 *************** B13(a/b) ORDERED BETA REGRESSIONS (Fairness demand) *************
 
 * OBS: Analysis in R-studio *
 
 
 /*
 
 rm(list=ls())


library(ordbetareg)
library(dplyr)
library(haven)
library(flextable)
library(officer)
library(dplyr)

Ukraine_warwel_survey_2023 <- read_dta("Final data\Ukraine_warwel_survey_2023_red_noid.dta")

# Filter the data where A12 < 3
filtered_data <- Ukraine_warwel_survey_2023 %>% filter(mov = 0)

filtered_data <- filtered_data %>%
 mutate(across(where(is.labelled), ~ as.numeric(.)))

# format dummy variables
filtered_data <- filtered_data  %>%
  mutate(across(c(gender, AgeGr6, edu3, retired, unemp, milvet, disab, 
                  pdam, IDP, urban, LANG, preA1n), as.factor))


# Table functions ---------------------------------------------------------

# Function to create formatted flextable
create_formatted_table <- function(df, title) {
  ft <- flextable(df) %>%
    theme_box() %>%
    autofit() %>%
    add_header_lines(values = title) %>%
    bold(part = "header") %>%
    align(align = "center", part = "header") %>%
    bg(bg = "#f2f2f2", part = "header") %>%
    border_outer(border = fp_border(color = "black", width = 2))
  
  return(ft)
}

# Create Word document
doc <- read_docx()

options(scipen=999)

# Add title to the document
doc <- doc %>%
  body_add_par("Marginal Effects", style = "heading 1") %>%
  body_add_par("") # Add blank line


# Estimate models + save marginal effects ---------------------------------

model1_obj <- ordbetareg(C1C ~ fat20gtwlnnorm, data = filtered_data)


mrgeffects <- marginaleffects::avg_slopes(model1_obj, variables="fat20gtwlnnorm")

# Add table
mrgeffects_table <- create_formatted_table(mrgeffects, "model1_obj")
doc <- doc %>%
  body_add_flextable(mrgeffects_table) %>%
  body_add_par("") # Add blank line

# 2. Including gender, AgeGr6, edu3, and incGr
model2_obj <- ordbetareg(C1C ~ fat20gtwlnnorm + gender + AgeGr6 + edu3 + incGr, 
                         data = filtered_data)

#modelsummary::modelsummary(model2_obj)

mrgeffects <- marginaleffects::avg_slopes(model2_obj, variables="fat20gtwlnnorm")

# Add table
mrgeffects_table <- create_formatted_table(mrgeffects, "model2_obj")
doc <- doc %>%
  body_add_flextable(mrgeffects_table) %>%
  body_add_par("") # Add blank line


# 3. Full model including additional covariates
model3_obj <- ordbetareg(C1C ~ fat20gtwlnnorm + gender + AgeGr6 + edu3 + incGr + 
                           HHsize + retired + unemp + milvet + disab + pdam + IDP + 
                           urban + LANG + preA1n, data = filtered_data)

mrgeffects <- marginaleffects::avg_slopes(model3_obj, variables="fat20gtwlnnorm")

# Add table
mrgeffects_table <- create_formatted_table(mrgeffects, "model3_obj")
doc <- doc %>%
  body_add_flextable(mrgeffects_table) %>%
  body_add_par("") # Add blank line


# Subjective regressions
# 1. Simple model
model1_subj <- ordbetareg(C1C ~ B1invnorm, data = filtered_data)

mrgeffects <- marginaleffects::avg_slopes(model1_subj, variables="B1invnorm")

# Add table
mrgeffects_table <- create_formatted_table(mrgeffects, "model1_subj")
doc <- doc %>%
  body_add_flextable(mrgeffects_table) %>%
  body_add_par("") # Add blank line


# 2. Including gender, AgeGr6, edu3, and incGr
model2_subj <- ordbetareg(C1C ~ B1invnorm + gender + AgeGr6 + edu3 + incGr, 
                          data = filtered_data)

mrgeffects <- marginaleffects::avg_slopes(model2_subj, variables="B1invnorm")

# Add table
mrgeffects_table <- create_formatted_table(mrgeffects, "model2_subj")
doc <- doc %>%
  body_add_flextable(mrgeffects_table) %>%
  body_add_par("") # Add blank line

# 3. Full model including additional covariates
model3_subj <- ordbetareg(C1C ~ B1invnorm + gender + AgeGr6 + edu3 + incGr + 
                            HHsize + retired + unemp + milvet + disab + pdam + IDP + 
                            urban + LANG + preA1n, data = filtered_data)

mrgeffects <- marginaleffects::avg_slopes(model3_subj, variables="B1invnorm")

# Add table
mrgeffects_table <- create_formatted_table(mrgeffects, "model3_subj")
doc <- doc %>%
  body_add_flextable(mrgeffects_table) %>%
  body_add_par("") # Add blank line

# Save the document
print(doc, target = "Appendix output\table_A13a.docx")

# Marginal effects -------------------------------------------------------

models <- list(model1_obj,
               model2_obj,
               model3_obj)

modelsummary::modelsummary(models, output = "Appendix output\table_A13b_obj.docx")

models <- list(model1_subj,
               model2_subj,
               model3_subj)

modelsummary::modelsummary(models, output = "Appendix output\table_A13b_subj.docx")

*/
 
 
 

 

************ War exposure - simplified operationalization **********

	**** TABLE B14 ****
	
	use "Ukraine_warwel_survey_2023_red_noid.dta", clear

* No time weights (only spatial); simple rowmean implies declining spatial weights
egen fat20gln=rowmean(fat5ln fat10ln fat20ln)
	
	*Normalize
	sum fat20gln, det
	gen fat20glnnorm = (fat20gln - r(min)) / (r(max)-r(min))
	label var fat20glnnorm "Logged fatalities 5-20km (normaliz.)"
		
	*Check correlation
	pwcorr fat20glnnorm fat20gtwlnnorm
	*0.93
	
* Simple fat20ln (normalized)
sum fat20ln, det
gen fat20lnnorm = (fat20ln - r(min)) / (r(max)-r(min))
label var fat20lnnorm "Logged fatalities, 20km (normaliz.)"


*** No time-weights, spatial graduation / No time-weights, no spatial graduation

eststo: regress relsocprio fat20glnnorm i.gender i.AgeGr6 i.edu3 ///
 incGr if mov==0, vce(cl ADM4nom)
eststo:  regress relsocprio fat20lnnorm i.gender i.AgeGr6 i.edu3 ///
 incGr if mov==0, vce(cl ADM4nom)
 
 
eststo: regress relnatalt fat20glnnorm i.gender i.AgeGr6 i.edu3 ///
 incGr if mov==0, vce(cl ADM4nom)
eststo: regress relnatalt fat20lnnorm i.gender i.AgeGr6 i.edu3 ///
 incGr if mov==0, vce(cl ADM4nom)
 
eststo: regress C1C fat20glnnorm i.gender i.AgeGr6 i.edu3 ///
 incGr if mov==0, vce(cl ADM4nom)
eststo: regress C1C fat20lnnorm i.gender i.AgeGr6 i.edu3 ///
 incGr if mov==0, vce(cl ADM4nom)
 
 	esttab using "Appendix output\table_B6-16.rtf", se r2 b(3) nogaps compress ///
 title("Table B14: Direct war exposure - simplified operationalizations") ///
 order(fat20glnnorm fat20lnnorm) nobase ///
 addnote("Standard errors clustered on locality in all models.") append
  eststo clear
  
  
 
 
	
	**** TABLE B15: Alternative war exposure source (UCDP) ****
	
	use "Ukraine_warwel_survey_2023_red_noid.dta", clear
	
eststo:	regress relsocprio fat20gtwlnnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0, vce(cl ADM4nom)
eststo: regress relsocprio Ufat20gtwlnnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0, vce(cl ADM4nom)

eststo: regress relnatalt fat20gtwlnnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0, vce(cl ADM4nom)
eststo: regress relnatalt Ufat20gtwlnnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0, vce(cl ADM4nom)

eststo: regress C1C fat20gtwlnnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0, vce(cl ADM4nom)
eststo: regress C1C Ufat20gtwlnnorm i.gender i.AgeGr6 i.edu3 incGr if mov==0, vce(cl ADM4nom)
 
 
  	esttab using "Appendix output\table_B6-16.rtf", se r2 b(3) nogaps compress ///
 title("Table B15: Direct war exposure - original (ACLED) and alternative data source (UCDP)") ///
 order(fat20gtwlnnorm Ufat20gtwlnnorm) nobase ///
 addnote("Standard errors clustered on locality in all models.") append
  eststo clear
 
 
 

 
	**** TABLE B16: Extended sample ****
	
 	use "Ukraine_warwel_survey_2023_red_noid.dta", clear
 
eststo: regress relsocprio fat20gtwlnnorm i.gender i.AgeGr6 i.edu3 incGr, vce(cl ADM4nom)
eststo: regress relsocprio B1invnorm i.gender i.AgeGr6 i.edu3 incGr

eststo: regress relnatalt fat20gtwlnnorm i.gender i.AgeGr6 i.edu3 incGr, vce(cl ADM4nom)
eststo: regress relnatalt B1invnorm i.gender i.AgeGr6 i.edu3 incGr

eststo: regress C1C fat20gtwlnnorm i.gender i.AgeGr6 i.edu3 incGr, vce(cl ADM4nom)
eststo: regress C1C B1invnorm i.gender i.AgeGr6 i.edu3 incGr 
 
   	esttab using "Appendix output\table_B6-16.rtf", se r2 b(3) nogaps compress ///
 title("Table B16: Extended sample (including permanent/temporarily displaced) ") ///
 order(fat20gtwlnnorm B1invnorm) nobase ///
 addnote("Standard errors clustered on locality in models 1, 3, 5.") append
  eststo clear
 
 

	*End*